<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

use App\Http\Model\Type;
use DB;

class AppServiceProvider extends ServiceProvider
{
    /**
     * 处理前台分类数据
     */
    static public function getCatePid($pid=0)
    {

        $ctype = new Type();

        $data = $ctype->where('pid',$pid)->get();
        
        $arr = [];

        foreach ($data as $key => $value) {
            
            $value['sub'] = self::getCatePid($value['id']);

            $arr[] = $value;
        }
        return $arr;

    }



    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //

         //1 获取前台分类遍历的数据
        $laytype = self::getCatePid();

        view()->share('laytype',$laytype);

        $config = DB::table('sad_config')->first();

        view()->share('config',$config);
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
